export default {
	dateFormat: function(time, fmt) {
		if(!time) {
			return "";
		}
		var d = new Date(time);
		var o = {
			"M+": d.getMonth() + 1, //月份   
			"d+": d.getDate(), //日   
			"z+": d.getDate() - 1, //昨日
			"h+": d.getHours(), //小时   
			"m+": d.getMinutes(), //分   
			"s+": d.getSeconds(), //秒   
			"q+": Math.floor((d.getMonth() + 3) / 3), //季度   
			"S": d.getMilliseconds() //毫秒   
		};
		if(/(y+)/.test(fmt))
			fmt = fmt.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
		for(var k in o)
			if(new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	},
	priceFormat: function(num) {
		if(!num) {
			return '0.00';
		}
		return String(Number(num).toFixed(2)).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
	},
	getUrlParams: function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg) || window.location.hash.substr(window.location.hash.indexOf("?") + 1).match(reg);
		if(r) {
			return decodeURI(r[2]);
		} else {
			return null;
		}
	},
	setHeader: function(header) {
		document.querySelector('title').innerHTML = header;
		//		// 判断是否是IOS
		//		var u = navigator.userAgent;
		//		if(!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
		//			changeTitle(header);
		//		}
	},
	getArrItem(arr, value, getItemKey, key) {
		for(var i = 0, len = arr.length; i < len; i++) {
			if(arr[i][getItemKey] == value) {
				return arr[i][key];
				break;
			}
		}
	},
	scrolls: function(scroll, container, callback) {
		var scroll = document.querySelector(scroll);
		var outerScroller = document.querySelector(container);
		var touchStart = 0;
		var touchDis = 0;
		outerScroller.addEventListener('touchstart', function(event) {
			var touch = event.targetTouches[0];
			// 把元素放在手指所在的位置 
			touchStart = touch.pageY;
		}, false);
		outerScroller.addEventListener('touchmove', function(event) {
			var touch = event.targetTouches[0];
			scroll.style.top = scroll.offsetTop + touch.pageY - touchStart + 'px';
			touchStart = touch.pageY;
			touchDis = touch.pageY - touchStart;
		}, false);
		outerScroller.addEventListener('touchend', function(event) {
			touchStart = 0;
			callback(top, scroll);
		}, false);
	},
	arrIsHasItem(path) {
		var res = true;
		var arr = ['login', 'product_classify', 'register', 'forgot', 'index', 'list', 'detail', 'store', 'vip'];
		for(var i = 0, len = arr.length; i < len; i++) {
			if(path.indexOf(arr[i]) < 0 && path != '/') {
				res = true;
			} else {
				res = false;
				break;
			}
		}
		return res;
	}
}